
import mcpi.minecraft as minecraft
import mcpi.block as block
import time
mc = minecraft.Minecraft.create("192.168.1.113",name = "sima")
pos = mc.player.getTilePos()


import random

sx = 38
sy = 38
maze_x = 2*sx + 1
maze_y = 2*sy + 1
dfs = [[0 for col in range(sx)] for row in range(sy)]
maze = [[0 for col in range(2*sx+1)] for row in range(2*sy+1)]
#1:up 2:down 3:left 4:right
operation = {1:(0,-1),2:(0,1),3:(-1,0),4:(1,0)}
direction = [1, 2, 3, 4]
stack = []

for i in range(2*sx+1):
    if i%2 == 0:
        for j in range(2*sx+1):
            maze[i][j] = 1
for i in range(2*sy+1):
    if i%2 == 0:
        for j in range(2*sy+1):
            maze[j][i] = 1
def generateMaze(start):
    x, y = start
    dfs[y][x] = 1
    random.shuffle(direction)
    for d in direction:
        px, py = (x + y for x, y in zip(start, operation[d]))
        if px < 0 or px >= sx or py < 0 or py >= sy:
            pass
        else:
            if dfs[py][px] is not 1:
                mx = 2*x + 1
                my = 2*y + 1
                if d == 1:
                    maze[my-1][mx] = 0
                elif d == 2:
                    maze[my+1][mx] = 0
                elif d == 3:
                    maze[my][mx-1] = 0
                elif d == 4:
                    maze[my][mx+1] = 0
                generateMaze((px,py))
                xx = px
                yy = py

generateMaze((0,0))
maze[0][1] = 0
maze[maze_x-2][maze_y-1] = 0

x0 = pos.x+1
y0 = pos.y
z0 = pos.z+1


for i in range(maze_x):
    for j in range(maze_y):
       if maze[i][j]==0:
        idd = 0
       elif maze[i][j] == 1:
        idd = 2
    mc.setBlock(x0+i,y0,z0+j,idd)
    mc.setBlock(x0+i,y0+1,z0+j,idd)
    mc.setBlock(x0+i,y0-1,z0+j,idd)
    mc.setBlock(x0+i,y0+2,z0+j,2)
































